home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / Proto Templates / protoTable-2 / README.protoTable < prev   
Encoding:
Text File  |  1994-02-28  |  2.7 KB  |  78 lines  |  [TEXT/R*ch]

  1. Copyright © 1993-94 Apple Computer, Inc. All rights reserved.
  2. Maurice Sharp
  3.  
  4. NTK 1.0.
  5.  
  6. So here is a protoTable example for your enjoyment.
  7.  
  8. This one will scroll up and down (though see TODO) and update a static text
  9. with the currently selected item in the table.
  10.  
  11. Before you read the explanation below, make sure you know about protoApp,
  12. protoStaticText and the Allow Access From (Declare) mechanism. You should
  13. also read the docs on protoTable and setting up the table definition (though
  14. you can also look at the viewSetupFormScript of the protoTable).
  15.  
  16.  
  17. Scrolling
  18. ---------
  19.  
  20. This is mostly done for you. What you have to do is add a viewScrollUpScript and
  21. viewScrollDownScript to your base application that just calls the
  22. same script in the protoTable. See those scripts in the protoApp.
  23.  
  24. I also use the scroll scripts to do local scrolling. In other words,the arrow
  25. buttons to the side of the table simply call the viewScrollUp/DownScript of
  26. the table. Neat huh?
  27.  
  28.  
  29. WARNING:
  30. Due to the way scrolling is implemented by the protoTable, it is possible
  31. to 'loose' the last item in the list. In reality, the last item is not lost,
  32. it is there but can not be shown due to rounding error.
  33.  
  34. The problem is in the viewScrollDownScript, however you can replace it with
  35. this one (both this function and the default one assume that tabHeights
  36. is an integer and NOT an array):
  37.  
  38.  
  39. func()
  40. begin
  41.     local biggestTop;
  42.     local temp := ((viewBounds.bottom - viewBounds.top) / def.tabHeights);
  43.     temp := if (temp - Floor(temp)) < 0.5 then Floor(temp) else Floor(temp) + 1 ;
  44.     biggestTop := Max(0, def.tabDown - temp) ;
  45.  
  46.     if vOrg < biggestTop then
  47.     begin
  48.         vOrg := vOrg + scrollAmount;
  49.         if vOrg > biggestTop then
  50.             vOrg := biggestTop ;
  51.         tabbase:RedoChildren();
  52.         :updateSelection();
  53.     end;
  54. end
  55.  
  56.  
  57. NOTE: The default scripts provided by the protoTable prototype assume that
  58.       the protoTable is Top Left parent releative justified. If you use some
  59.       other form of justification, one or both of the default scrolling
  60.       functions will break. You will have to write your own wrapper function
  61.       that figures out if you should call the protoTable scrolling functions.
  62.       
  63. Updating With New Selection
  64. ---------------------------
  65.  
  66. This one is a bit skankier... protoTable has an optional slot called
  67. currentSelection. This should initially be nil, and will be set to the
  68. item in the tabValues array that is currently selected in the table. It
  69. is updated each time a selection is made.
  70.  
  71. In order to update the static text item whenever a selection is made,
  72. I specialize the selectThisCell message. NOTE: I specialize it (i.e.,
  73. I do an inherited:selectThisCell call). If you fail to do this BAD
  74. things will happen.
  75.  
  76. So look at the selectThisCell message in the protoTable. Also notice the
  77. currentSelection slot with a nil value.
  78.